(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 11.2' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[     32752,        733]
NotebookOptionsPosition[     30604,        690]
NotebookOutlinePosition[     30973,        706]
CellTagsIndexPosition[     30930,        703]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
 RowBox[{
  RowBox[{"KiB", "=", 
   SuperscriptBox["2", "10"]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"MiB", "=", 
   SuperscriptBox["KiB", "2"]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"GiB", "=", 
   SuperscriptBox["MiB", "2"]}], ";"}]}], "Input",
 CellChangeTimes->{{3.789275444300604*^9, 3.789275457059833*^9}, {
  3.789275656221854*^9, 3.7892756678777018`*^9}, {3.789403289313239*^9, 
  3.7894032914805193`*^9}, {3.789465515208022*^9, 
  3.7894655153674*^9}},ExpressionUUID->"04e5085a-4ff9-4d50-b19b-083b558526b6"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"contours", "=", 
  RowBox[{"Sort", "@", 
   RowBox[{"Flatten", "@", 
    RowBox[{"Table", "[", 
     RowBox[{
      RowBox[{
       RowBox[{"{", 
        SuperscriptBox["2", "n"], "}"}], "//", "N"}], ",", 
      RowBox[{"{", 
       RowBox[{"n", ",", "1", ",", "20", ",", "1"}], "}"}]}], 
     "]"}]}]}]}]], "Input",
 CellChangeTimes->{{3.789281841342827*^9, 3.789281843934923*^9}, {
   3.7892818960555477`*^9, 3.7892819064149*^9}, {3.789282106418557*^9, 
   3.789282233202319*^9}, 3.789282450548361*^9, {3.789283908617794*^9, 
   3.789283909155002*^9}, {3.7892858156032877`*^9, 3.7892858276670523`*^9}, {
   3.789285893388174*^9, 3.789285893523487*^9}, {3.789286153337405*^9, 
   3.789286162102024*^9}, {3.7893761416637173`*^9, 
   3.789376141818184*^9}},ExpressionUUID->"ea6f14b4-a2fb-45ea-a4c3-\
bd72323380f9"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{
  "2.`", ",", "4.`", ",", "8.`", ",", "16.`", ",", "32.`", ",", "64.`", ",", 
   "128.`", ",", "256.`", ",", "512.`", ",", "1024.`", ",", "2048.`", ",", 
   "4096.`", ",", "8192.`", ",", "16384.`", ",", "32768.`", ",", "65536.`", 
   ",", "131072.`", ",", "262144.`", ",", "524288.`", ",", "1.048576`*^6"}], 
  "}"}]], "Output",
 CellChangeTimes->{
  3.789281916671997*^9, {3.789282117037916*^9, 3.78928223366226*^9}, 
   3.78928245119182*^9, 3.7892827648916407`*^9, 3.789283911746563*^9, 
   3.7892858284229517`*^9, 3.789285893970244*^9, 3.789286162985887*^9, 
   3.789287702623497*^9, 3.789291024997972*^9, 3.789291297851441*^9, 
   3.789291551278347*^9, 3.789291986653308*^9, 3.7893007525178947`*^9, 
   3.789301848763577*^9, 3.789374132622946*^9, 3.7893745177246723`*^9, 
   3.7893761422674103`*^9, {3.789376414615366*^9, 3.7893764432982483`*^9}, 
   3.789377680114626*^9, 3.78937792705991*^9, 3.789402829808154*^9, 
   3.789405267046749*^9},ExpressionUUID->"6cdc7651-732c-497e-9a81-\
da71969e4fba"]
}, Open  ]],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"log2", "[", "x_", "]"}], ":=", 
   RowBox[{"Block", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"$MaxExtraPrecision", "=", "1000"}], "}"}], ",", 
     RowBox[{"Log2", "[", "x", "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"logscale", "[", 
    RowBox[{"x_", ",", "min_", ",", "max_"}], "]"}], ":=", 
   FractionBox[
    RowBox[{"Log", "[", 
     RowBox[{"x", "/", "min"}], "]"}], 
    RowBox[{"Log", "[", 
     RowBox[{"max", "/", "min"}], "]"}]]}], ";"}]}], "Input",
 CellChangeTimes->{{3.789284713668509*^9, 3.7892847532889557`*^9}, {
   3.789285122644882*^9, 3.789285131324595*^9}, {3.789405086849925*^9, 
   3.789405106713532*^9}, 
   3.7894063182932053`*^9},ExpressionUUID->"7ba8422a-20a9-495a-a0c7-\
5edcaa0eb031"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"fun", "[", 
    RowBox[{"M_", ",", "n_", ",", "l_", ",", "a_"}], "]"}], ":=", 
   RowBox[{
    RowBox[{"a", " ", 
     RowBox[{"(", 
      RowBox[{"1", "+", 
       RowBox[{"Ceiling", "[", 
        FractionBox["M", "l"], "]"}], "-", 
       RowBox[{"Ceiling", "[", 
        FractionBox["n", "l"], "]"}]}], ")"}]}], "+", 
    FractionBox[
     RowBox[{"2", " ", "l", " ", "n", " ", 
      RowBox[{"Ceiling", "[", 
       FractionBox["M", "l"], "]"}], " ", 
      RowBox[{"(", 
       RowBox[{"1", "+", 
        RowBox[{"Ceiling", "[", 
         RowBox[{"log2", "[", 
          RowBox[{"Ceiling", "[", 
           FractionBox["n", "l"], "]"}], "]"}], "]"}]}], ")"}]}], 
     RowBox[{"l", "+", "n"}]]}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"makeOne", "[", 
    RowBox[{"scale_", ",", "units_", ",", "l_", ",", "a_", ",", 
     RowBox[{"step_:", "10"}]}], "]"}], ":=", 
   RowBox[{"Module", "[", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"tab", ",", "Hmin", ",", "Hmax"}], "}"}], ",", 
     "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"tab", "=", 
       RowBox[{"Flatten", "[", 
        RowBox[{
         RowBox[{"ParallelTable", "[", "\[IndentingNewLine]", 
          RowBox[{
           RowBox[{
            RowBox[{"{", 
             RowBox[{"M", ",", 
              SuperscriptBox["2", "lg2n"], ",", 
              RowBox[{
               RowBox[{"fun", "[", 
                RowBox[{
                 RowBox[{"M", " ", "scale"}], ",", 
                 RowBox[{
                  SuperscriptBox["2", "lg2n"], "scale"}], ",", "l", ",", 
                 "a"}], "]"}], "/", "scale"}]}], "}"}], "//", "N"}], ",", 
           "\[IndentingNewLine]", 
           RowBox[{"{", 
            RowBox[{"lg2n", ",", 
             RowBox[{"Log2", "[", "0.1", "]"}], ",", 
             RowBox[{"Log2", "[", "100", "]"}], ",", 
             RowBox[{
              SuperscriptBox["10", 
               RowBox[{"-", "3"}]], "step"}]}], "}"}], ",", 
           "\[IndentingNewLine]", 
           RowBox[{"{", 
            RowBox[{"M", ",", "10", ",", "1000", ",", "step"}], " ", "}"}]}], 
          "\[IndentingNewLine]", "]"}], ",", "1"}], "]"}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"Hmin", "=", 
       RowBox[{"Min", "[", 
        RowBox[{
         RowBox[{"tab", "\[Transpose]"}], "[", 
         RowBox[{"[", "3", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
      
      RowBox[{"Hmax", "=", 
       RowBox[{"Max", "[", 
        RowBox[{
         RowBox[{"tab", "\[Transpose]"}], "[", 
         RowBox[{"[", "3", "]"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
      
      RowBox[{"Print", "[", 
       RowBox[{"{", 
        RowBox[{"Hmax", ",", "Hmin"}], "}"}], "]"}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{"(*", " ", 
       RowBox[{
        RowBox[{"https", ":"}], "//", 
        RowBox[{
         RowBox[{
          RowBox[{
           RowBox[{
            RowBox[{"mathematica", ".", "stackexchange", ".", "com"}], "/", 
            "questions"}], "/", "185099"}], "/", "regionfunction"}], "-", 
         "doesnt", "-", "work", "-", "in", "-", "listcontourplot", "-", "if", 
         "-", "also", "-", "using", "-", "scalingfunctions"}]}], " ", "*)"}], 
      "\[IndentingNewLine]", 
      RowBox[{"ListDensityPlot", "[", "\[IndentingNewLine]", 
       RowBox[{"tab", ",", "\[IndentingNewLine]", 
        RowBox[{"PlotTheme", "\[Rule]", "\"\<Detailed\>\""}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"ColorFunction", "\[Rule]", 
         RowBox[{"(", 
          RowBox[{
           RowBox[{"Hue", "[", 
            RowBox[{"logscale", "[", 
             RowBox[{"#", ",", "Hmin", ",", "Hmax"}], "]"}], "]"}], "&"}], 
          ")"}]}], ",", "\[IndentingNewLine]", 
        RowBox[{"ColorFunctionScaling", "\[Rule]", "False"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"FrameLabel", "\[Rule]", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"StringForm", "[", 
            RowBox[{"\"\<M [``]\>\"", ",", "units"}], "]"}], ",", 
           RowBox[{"StringForm", "[", 
            RowBox[{"\"\<n [``]\>\"", ",", "units"}], "]"}]}], "}"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"LabelStyle", "\[Rule]", 
         RowBox[{"Directive", "[", "Black", "]"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"ScalingFunctions", "\[Rule]", 
         RowBox[{"{", 
          RowBox[{"\"\<Log\>\"", ",", "\"\<Log\>\""}], "}"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"RegionFunction", "\[Rule]", 
         RowBox[{"Function", "[", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{"M", ",", "n", ",", "H"}], "}"}], ",", 
           RowBox[{
            RowBox[{"Exp", "[", "M", "]"}], "\[GreaterEqual]", 
            RowBox[{"2", " ", 
             RowBox[{"Exp", "[", "n", "]"}]}]}]}], "]"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"GridLines", "\[Rule]", "Automatic"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"ImageSize", "->", "Medium"}], ",", "\[IndentingNewLine]", 
        RowBox[{"MeshFunctions", "\[Rule]", 
         RowBox[{"{", 
          RowBox[{"Function", "[", 
           RowBox[{
            RowBox[{"{", 
             RowBox[{"M", ",", "n", ",", "H"}], "}"}], ",", 
            RowBox[{"Ceiling", "@", 
             RowBox[{"Log2", "[", "H", "]"}]}]}], "]"}], "}"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"Mesh", "\[Rule]", 
         RowBox[{"(", 
          RowBox[{
           RowBox[{"Ceiling", "@", 
            RowBox[{"Log2", "[", "Hmax", "]"}]}], "-", 
           RowBox[{"Ceiling", "@", 
            RowBox[{"Log2", "[", "Hmin", "]"}]}]}], ")"}]}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"MeshStyle", "\[Rule]", 
         RowBox[{"Directive", "[", 
          RowBox[{"Black", ",", "Thin"}], "]"}]}], ",", "\[IndentingNewLine]", 
        RowBox[{"PlotLegends", "\[Rule]", 
         RowBox[{"BarLegend", "[", 
          RowBox[{
           RowBox[{"{", 
            RowBox[{
             RowBox[{
              RowBox[{"Hue", "[", 
               RowBox[{"logscale", "[", 
                RowBox[{"#", ",", "Hmin", ",", "Hmax"}], "]"}], "]"}], "&"}], 
             ",", 
             RowBox[{"{", 
              RowBox[{"Hmin", ",", "Hmax"}], "}"}]}], "}"}], ",", "contours", 
           ",", 
           RowBox[{"LegendLabel", "\[Rule]", 
            RowBox[{"StringForm", "[", 
             RowBox[{"\"\<H [``]\>\"", ",", "units"}], "]"}]}]}], "]"}]}], 
        ",", "\[IndentingNewLine]", 
        RowBox[{"PlotLabel", "\[Rule]", 
         RowBox[{"StringForm", "[", 
          RowBox[{"\"\<l=`` bytes, a=`` bytes\>\"", ",", "l", ",", "a"}], 
          "]"}]}]}], "\[IndentingNewLine]", "]"}]}]}], "\[IndentingNewLine]", 
    "]"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.789280246056041*^9, 3.789280356130279*^9}, {
   3.789280408073968*^9, 3.789280425665655*^9}, {3.7892804691541224`*^9, 
   3.789280476034214*^9}, {3.789280522658839*^9, 3.789280683148141*^9}, {
   3.7892807636451273`*^9, 3.789280818693698*^9}, {3.789280935206689*^9, 
   3.7892809835668488`*^9}, 3.789281174993402*^9, {3.7892812932979937`*^9, 
   3.789281319722005*^9}, {3.789281385194892*^9, 3.789281402572263*^9}, {
   3.789281438675259*^9, 3.789281439458931*^9}, {3.789281504684125*^9, 
   3.789281505075845*^9}, 3.789281568996512*^9, 3.789281631868816*^9, {
   3.7892817781503983`*^9, 3.789281801757922*^9}, 3.789281849559395*^9, {
   3.789282027072892*^9, 3.789282073416997*^9}, {3.78928235606789*^9, 
   3.78928240201987*^9}, {3.789282545717617*^9, 3.789282546093277*^9}, {
   3.789282579301997*^9, 3.7892825882616653`*^9}, {3.78928273347156*^9, 
   3.789282745479192*^9}, {3.7892829477771063`*^9, 3.7892830361657248`*^9}, {
   3.789283133299006*^9, 3.789283133562696*^9}, {3.7892831886751966`*^9, 
   3.789283235715763*^9}, {3.789283283364522*^9, 3.789283291596423*^9}, {
   3.789283447749753*^9, 3.789283449760581*^9}, {3.7892835081344357`*^9, 
   3.789283508470191*^9}, {3.78928362463173*^9, 3.789283625535357*^9}, {
   3.789283782088828*^9, 3.789283846513686*^9}, {3.789283884921986*^9, 
   3.789283889522051*^9}, {3.7892839441385927`*^9, 3.789283945210472*^9}, {
   3.7892840102113123`*^9, 3.789284010522828*^9}, {3.7892840464112864`*^9, 
   3.78928408977178*^9}, {3.789284183564673*^9, 3.789284201604988*^9}, {
   3.789284264340958*^9, 3.7892842826213713`*^9}, {3.7892844098626127`*^9, 
   3.789284445575037*^9}, {3.789284501135831*^9, 3.789284511144747*^9}, {
   3.789284585944355*^9, 3.789284590144384*^9}, {3.789284655569034*^9, 
   3.789284704549354*^9}, {3.7892847592187223`*^9, 3.7892847620017977`*^9}, {
   3.78928479292568*^9, 3.789284796610289*^9}, {3.789284870259262*^9, 
   3.7892848976269836`*^9}, {3.7892849494116783`*^9, 3.789284951339712*^9}, {
   3.789285037740828*^9, 3.78928504397268*^9}, {3.78928546552855*^9, 
   3.789285469089245*^9}, {3.7892855250892563`*^9, 3.78928553684094*^9}, {
   3.789285569713491*^9, 3.789285576009612*^9}, {3.789285636154397*^9, 
   3.789285686466618*^9}, {3.789285766533196*^9, 3.789285798523879*^9}, {
   3.789285857204463*^9, 3.789285858100181*^9}, 3.7892859871849127`*^9, {
   3.7892860521021557`*^9, 3.789286059749999*^9}, {3.789286107230831*^9, 
   3.789286126566883*^9}, {3.789286686883875*^9, 3.789286690723843*^9}, {
   3.789286758500793*^9, 3.789286761532761*^9}, {3.789287707837248*^9, 
   3.7892877447100487`*^9}, {3.789287793358423*^9, 3.789287799958309*^9}, 
   3.789291032476109*^9, {3.789291173797717*^9, 3.789291175221747*^9}, {
   3.789291212150223*^9, 3.789291217374158*^9}, {3.789291306967759*^9, 
   3.789291321663067*^9}, {3.789291954373361*^9, 3.789291969020938*^9}, 
   3.7892920038299837`*^9, {3.789292045806203*^9, 3.789292124308773*^9}, {
   3.789292204815588*^9, 3.789292219255571*^9}, {3.7892922608563833`*^9, 
   3.7892922637677317`*^9}, {3.789300767054385*^9, 3.789300792119556*^9}, {
   3.789374140118495*^9, 3.789374158142015*^9}, {3.7893742691509857`*^9, 
   3.789374342120255*^9}, {3.78937439936021*^9, 3.789374428096511*^9}, {
   3.789374501569466*^9, 3.789374509081443*^9}, {3.7893748006041603`*^9, 
   3.789374814220223*^9}, {3.789374893813216*^9, 3.789374925197254*^9}, {
   3.789375034742609*^9, 3.789375049527357*^9}, {3.7893752646805887`*^9, 
   3.789375264880328*^9}, 3.789375706669462*^9, 3.7893760080168867`*^9, 
   3.789376125033499*^9, 3.78937621038498*^9, {3.7893762416413794`*^9, 
   3.7893762728576193`*^9}, {3.7893763360343227`*^9, 3.7893763500902967`*^9}, 
   3.789376438892367*^9, {3.7893765950852137`*^9, 3.789376635267338*^9}, {
   3.789376676845881*^9, 3.789376717486308*^9}, {3.789376754662531*^9, 
   3.78937675472582*^9}, {3.7893767865187798`*^9, 3.789376788406362*^9}, {
   3.789376826031127*^9, 3.7893768559595747`*^9}, {3.7893768975120173`*^9, 
   3.7893769525119247`*^9}, {3.789377253746799*^9, 3.7893772762108192`*^9}, {
   3.789377895912945*^9, 3.78937790204856*^9}, {3.7893942283422728`*^9, 
   3.789394261671871*^9}, {3.789402772077365*^9, 3.789402788797641*^9}, 
   3.789402825685789*^9, 3.789402900526267*^9, {3.789403059408598*^9, 
   3.789403072208037*^9}, {3.789404709351665*^9, 3.789404771223686*^9}, 
   3.789404802544241*^9, {3.7894051175728807`*^9, 3.7894051276192417`*^9}, {
   3.789405182156098*^9, 3.789405207573221*^9}, {3.789405238380477*^9, 
   3.789405238700159*^9}, {3.789406233021742*^9, 3.789406243765362*^9}, {
   3.789406340132078*^9, 3.7894063471265993`*^9}, 3.789459165431209*^9, {
   3.789459299063719*^9, 3.7894593623840437`*^9}, {3.789460698612677*^9, 
   3.7894607378448677`*^9}, {3.789461201281106*^9, 3.7894612021131*^9}, {
   3.789461255137965*^9, 3.789461266361767*^9}, {3.789461305818417*^9, 
   3.789461358250536*^9}, {3.789461393947421*^9, 3.789461491387927*^9}, {
   3.7894616096977654`*^9, 3.789461682917646*^9}, {3.78946176196677*^9, 
   3.789461776287026*^9}, {3.789463409446578*^9, 3.7894634293732643`*^9}, {
   3.789463508335032*^9, 3.789463518598549*^9}, {3.789463644064063*^9, 
   3.7894636643200893`*^9}},ExpressionUUID->"fef9122d-67b4-458a-a3dc-\
0f08d8bc6a61"],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"step", "=", "10"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{"GraphicsGrid", "[", 
  RowBox[{
   RowBox[{"{", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       RowBox[{"makeOne", "[", 
        RowBox[{
        "KiB", ",", "\"\<KiB\>\"", ",", "16", ",", "16", ",", "step"}], "]"}],
        ",", 
       RowBox[{"makeOne", "[", 
        RowBox[{
        "MiB", ",", "\"\<MiB\>\"", ",", "16", ",", "16", ",", "step"}], 
        "]"}]}], "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{
       RowBox[{"makeOne", "[", 
        RowBox[{
        "KiB", ",", "\"\<KiB\>\"", ",", "32", ",", "32", ",", "step"}], "]"}],
        ",", 
       RowBox[{"makeOne", "[", 
        RowBox[{
        "MiB", ",", "\"\<MiB\>\"", ",", "32", ",", "32", ",", "step"}], 
        "]"}]}], "}"}]}], "\[IndentingNewLine]", "}"}], ",", 
   RowBox[{"Spacings", "\[Rule]", "0"}], ",", 
   RowBox[{"Frame", "\[Rule]", "None"}]}], "]"}]}], "Input",
 CellChangeTimes->{
  3.7894047673182*^9, {3.7894048078065643`*^9, 3.789404823840007*^9}, {
   3.7894048541911592`*^9, 3.7894048886172123`*^9}, {3.789405251395466*^9, 
   3.7894053094593287`*^9}, {3.789406363326427*^9, 3.789406386789246*^9}, {
   3.789406448095297*^9, 3.7894064573978443`*^9}, {3.78945904802888*^9, 
   3.789459063147698*^9}, {3.789459099381216*^9, 3.789459113004238*^9}, {
   3.789459206437985*^9, 3.789459269903431*^9}, {3.78945952508218*^9, 
   3.7894595370653677`*^9}, {3.789459934965631*^9, 3.78945999119464*^9}, {
   3.7894634977650967`*^9, 3.78946349915244*^9}, {3.789463673202278*^9, 
   3.789463674054624*^9}, {3.789463825370187*^9, 3.78946382766597*^9}, {
   3.7894642094772797`*^9, 
   3.7894642187474546`*^9}},ExpressionUUID->"0b3bb483-359c-4254-9b33-\
4236a01c1ffa"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"28928.860102855793`", ",", "79.09543918918918`"}], "}"}]], "Print",\

 CellChangeTimes->{{3.789404809298462*^9, 3.789404824978161*^9}, {
   3.789404857133449*^9, 3.789404889483738*^9}, 3.789405166368128*^9, {
   3.789405226669142*^9, 3.789405310147141*^9}, {3.789406367598962*^9, 
   3.789406387641362*^9}, {3.789406449656837*^9, 3.789406458125374*^9}, 
   3.789459067170635*^9, {3.7894591025024242`*^9, 3.7894591133438683`*^9}, 
   3.7894591946555443`*^9, {3.789459244726068*^9, 3.7894592707823563`*^9}, 
   3.789459363594998*^9, 3.789459525850275*^9, {3.789459985423051*^9, 
   3.7894599923173943`*^9}, 3.7894607081453114`*^9, 3.7894612039481688`*^9, 
   3.789461268038295*^9, 3.789461313798089*^9, {3.789461345957137*^9, 
   3.78946136068554*^9}, {3.7894613984203043`*^9, 3.789461425270396*^9}, {
   3.789461460211883*^9, 3.7894614924915*^9}, {3.7894616254116096`*^9, 
   3.789461684194468*^9}, {3.789461763988781*^9, 3.789461777609152*^9}, {
   3.789463416850573*^9, 3.78946343101101*^9}, 3.789463674608634*^9, 
   3.789463828585515*^9, 
   3.7894642497896423`*^9},ExpressionUUID->"f7471907-0dcc-4cfc-913a-\
1f30bcc63050"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"48935.629549937796`", ",", "289.8409466320586`"}], "}"}]], "Print",\

 CellChangeTimes->{{3.789404809298462*^9, 3.789404824978161*^9}, {
   3.789404857133449*^9, 3.789404889483738*^9}, 3.789405166368128*^9, {
   3.789405226669142*^9, 3.789405310147141*^9}, {3.789406367598962*^9, 
   3.789406387641362*^9}, {3.789406449656837*^9, 3.789406458125374*^9}, 
   3.789459067170635*^9, {3.7894591025024242`*^9, 3.7894591133438683`*^9}, 
   3.7894591946555443`*^9, {3.789459244726068*^9, 3.7894592707823563`*^9}, 
   3.789459363594998*^9, 3.789459525850275*^9, {3.789459985423051*^9, 
   3.7894599923173943`*^9}, 3.7894607081453114`*^9, 3.7894612039481688`*^9, 
   3.789461268038295*^9, 3.789461313798089*^9, {3.789461345957137*^9, 
   3.78946136068554*^9}, {3.7894613984203043`*^9, 3.789461425270396*^9}, {
   3.789461460211883*^9, 3.7894614924915*^9}, {3.7894616254116096`*^9, 
   3.789461684194468*^9}, {3.789461763988781*^9, 3.789461777609152*^9}, {
   3.789463416850573*^9, 3.78946343101101*^9}, 3.789463674608634*^9, 
   3.789463828585515*^9, 
   3.789464260074924*^9},ExpressionUUID->"b33ddc99-242a-47c1-aa6c-\
83693b6605bb"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"26923.03789659599`", ",", "55.620535714285715`"}], "}"}]], "Print",\

 CellChangeTimes->{{3.789404809298462*^9, 3.789404824978161*^9}, {
   3.789404857133449*^9, 3.789404889483738*^9}, 3.789405166368128*^9, {
   3.789405226669142*^9, 3.789405310147141*^9}, {3.789406367598962*^9, 
   3.789406387641362*^9}, {3.789406449656837*^9, 3.789406458125374*^9}, 
   3.789459067170635*^9, {3.7894591025024242`*^9, 3.7894591133438683`*^9}, 
   3.7894591946555443`*^9, {3.789459244726068*^9, 3.7894592707823563`*^9}, 
   3.789459363594998*^9, 3.789459525850275*^9, {3.789459985423051*^9, 
   3.7894599923173943`*^9}, 3.7894607081453114`*^9, 3.7894612039481688`*^9, 
   3.789461268038295*^9, 3.789461313798089*^9, {3.789461345957137*^9, 
   3.78946136068554*^9}, {3.7894613984203043`*^9, 3.789461425270396*^9}, {
   3.789461460211883*^9, 3.7894614924915*^9}, {3.7894616254116096`*^9, 
   3.789461684194468*^9}, {3.789461763988781*^9, 3.789461777609152*^9}, {
   3.789463416850573*^9, 3.78946343101101*^9}, 3.789463674608634*^9, 
   3.789463828585515*^9, 
   3.789464269976918*^9},ExpressionUUID->"e212f8f0-5ca0-4500-8fd4-\
33fb8eff3d19"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"46935.619118058145`", ",", "269.81163718766703`"}], "}"}]], "Print",\

 CellChangeTimes->{{3.789404809298462*^9, 3.789404824978161*^9}, {
   3.789404857133449*^9, 3.789404889483738*^9}, 3.789405166368128*^9, {
   3.789405226669142*^9, 3.789405310147141*^9}, {3.789406367598962*^9, 
   3.789406387641362*^9}, {3.789406449656837*^9, 3.789406458125374*^9}, 
   3.789459067170635*^9, {3.7894591025024242`*^9, 3.7894591133438683`*^9}, 
   3.7894591946555443`*^9, {3.789459244726068*^9, 3.7894592707823563`*^9}, 
   3.789459363594998*^9, 3.789459525850275*^9, {3.789459985423051*^9, 
   3.7894599923173943`*^9}, 3.7894607081453114`*^9, 3.7894612039481688`*^9, 
   3.789461268038295*^9, 3.789461313798089*^9, {3.789461345957137*^9, 
   3.78946136068554*^9}, {3.7894613984203043`*^9, 3.789461425270396*^9}, {
   3.789461460211883*^9, 3.7894614924915*^9}, {3.7894616254116096`*^9, 
   3.789461684194468*^9}, {3.789461763988781*^9, 3.789461777609152*^9}, {
   3.789463416850573*^9, 3.78946343101101*^9}, 3.789463674608634*^9, 
   3.789463828585515*^9, 
   3.789464279971678*^9},ExpressionUUID->"6c9741b5-da27-4705-a7a8-\
435eb2639de1"]
}, Open  ]]
}, Open  ]],

Cell[BoxData[{
 RowBox[{
  RowBox[{"M", ";"}], 
  RowBox[{"(*", " ", 
   RowBox[{
   "Total", " ", "memory", " ", "requirement", " ", "of", " ", "the", " ", 
    RowBox[{"application", "."}]}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"n", ";"}], 
  RowBox[{"(*", " ", 
   RowBox[{"Largest", " ", "allocation", " ", 
    RowBox[{"request", "."}]}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"a", ";", 
   RowBox[{"(*", " ", 
    RowBox[{"Metadata", " ", "overhead", " ", "per", " ", "allocation", " ", 
     RowBox[{
      RowBox[{"(", "O1HEAP_ALIGNMENT", ")"}], "."}]}], " ", "*)"}], 
   "\[IndentingNewLine]", "l", ";", 
   RowBox[{"(*", " ", 
    RowBox[{"Smallest", " ", "allocation", " ", 
     RowBox[{"size", "."}]}], " ", "*)"}], "\[IndentingNewLine]", 
   "\[IndentingNewLine]", 
   RowBox[{"nf", "=", 
    RowBox[{"Ceiling", "[", 
     FractionBox["n", "l"], "]"}]}], ";"}], " ", 
  RowBox[{"(*", " ", 
   RowBox[{
   "Number", " ", "of", " ", "fragments", " ", "in", " ", "the", " ", 
    "largest", " ", 
    RowBox[{"allocation", "."}]}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Mf", "=", 
   RowBox[{"Ceiling", "[", 
    FractionBox["M", "l"], "]"}]}], ";", " ", 
  RowBox[{"(*", " ", 
   RowBox[{
    RowBox[{
    "Total", " ", "memory", " ", "requirement", " ", "in", " ", "min"}], "-", 
    
    RowBox[{"sized", " ", "allocation", " ", 
     RowBox[{"fragments", "."}]}]}], " ", "*)"}], "\[IndentingNewLine]", 
  RowBox[{"k", "=", 
   RowBox[{"Mf", "-", "nf", "+", "1"}]}], ";", " ", 
  RowBox[{"(*", " ", 
   RowBox[{"Maximum", " ", 
    RowBox[{"(", 
     RowBox[{"worst", "-", "case"}], ")"}], " ", "number", " ", "of", " ", 
    RowBox[{"fragments", "."}]}], " ", "*)"}]}]}], "Input",
 CellChangeTimes->{{3.789392744279873*^9, 3.7893927720792503`*^9}, {
   3.789392835967842*^9, 3.789392898168564*^9}, {3.789392945985002*^9, 
   3.789392979185411*^9}, {3.7893930180977087`*^9, 3.789393157931241*^9}, {
   3.789393453302162*^9, 3.789393518478466*^9}, {3.789393603551305*^9, 
   3.789393656151812*^9}, {3.789393731520648*^9, 3.789393739960615*^9}, {
   3.789395392280179*^9, 3.7893954072032824`*^9}, {3.7893999841941833`*^9, 
   3.789400003467082*^9}, {3.789400033706933*^9, 3.789400036475082*^9}, {
   3.789460032693584*^9, 3.789460037652994*^9}, 3.789460383312705*^9, 
   3.789460446225297*^9, 3.789460623658257*^9, {3.789462311026473*^9, 
   3.7894623114657497`*^9}},ExpressionUUID->"c183fee1-f76a-49fb-9eba-\
406d0d314017"],

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"Hf", "=", 
    RowBox[{"2", "Mf", 
     RowBox[{"(", 
      RowBox[{"1", "+", 
       RowBox[{"Ceiling", "[", 
        RowBox[{"log2", "[", "nf", "]"}], "]"}]}], ")"}]}]}], ";"}], " ", 
  RowBox[{"(*", " ", 
   RowBox[{"The", " ", "required", " ", "number", " ", "of", " ", 
    RowBox[{"fragments", "."}]}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Hb", "=", 
   RowBox[{
    RowBox[{"Hf", " ", "l", 
     FractionBox["n", 
      RowBox[{"l", "+", "n"}]]}], "+", 
    RowBox[{"k", " ", "a"}]}]}], ";", " ", 
  RowBox[{"(*", " ", 
   RowBox[{"The", " ", "required", " ", "number", " ", "of", " ", 
    RowBox[{"Bytes", "."}]}], " ", "*)"}], "\[IndentingNewLine]"}]}], "Input",\

 CellChangeTimes->{{3.789393308844919*^9, 3.789393379821001*^9}, {
   3.7893943230299883`*^9, 3.7893943552699842`*^9}, {3.789394639944664*^9, 
   3.78939466527275*^9}, {3.789397196752596*^9, 3.7893972297926407`*^9}, {
   3.78940003031602*^9, 3.789400031370555*^9}, {3.789406259172673*^9, 
   3.7894062592119827`*^9}, 3.789460386952538*^9, 3.7894606269629*^9, {
   3.789460860372891*^9, 3.78946086825254*^9}, {3.789462046991984*^9, 
   3.789462058319696*^9}, {3.78946211693657*^9, 3.78946211949629*^9}, {
   3.789462167033181*^9, 3.789462168576659*^9}, {3.789463181498582*^9, 
   3.789463194305964*^9}, {3.7894632820035667`*^9, 3.7894632837949333`*^9}, {
   3.7894633319717817`*^9, 3.789463337307558*^9}, {3.789463381684073*^9, 
   3.789463383459941*^9}},ExpressionUUID->"9b89251b-6542-44c3-b076-\
f04565361aee"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"Hb", "//", "TraditionalForm"}]], "Input",
 CellChangeTimes->{{3.789393407365972*^9, 3.789393414738001*^9}, 
   3.789394667393249*^9, {3.789400149659919*^9, 3.789400151587311*^9}, 
   3.789400183291913*^9, {3.789402410288623*^9, 3.7894024331686907`*^9}, {
   3.7894026686992807`*^9, 3.7894026860277777`*^9}, 3.7894027587722683`*^9, {
   3.7894631184173803`*^9, 3.789463145369527*^9}, 3.789463175393835*^9, {
   3.789465417990759*^9, 
   3.789465472591196*^9}},ExpressionUUID->"392a23f7-4324-481d-849c-\
2aadb1bc67bf"],

Cell[BoxData[
 FormBox[
  RowBox[{
   RowBox[{"a", " ", 
    RowBox[{"(", 
     RowBox[{
      TemplateBox[{FractionBox["M", "l"]},
       "Ceiling"], "-", 
      TemplateBox[{FractionBox["n", "l"]},
       "Ceiling"], "+", "1"}], ")"}]}], "+", 
   FractionBox[
    RowBox[{"2", " ", "l", " ", "n", " ", 
     TemplateBox[{FractionBox["M", "l"]},
      "Ceiling"], " ", 
     RowBox[{"(", 
      RowBox[{
       TemplateBox[{FractionBox[
          RowBox[{"log", "(", 
            TemplateBox[{
              FractionBox["n", "l"]}, "Ceiling"], ")"}], 
          RowBox[{"log", "(", "2", ")"}]]},
        "Ceiling"], "+", "1"}], ")"}]}], 
    RowBox[{"l", "+", "n"}]]}], TraditionalForm]], "Output",
 CellChangeTimes->{{3.7894654680912523`*^9, 
  3.7894654729550257`*^9}},ExpressionUUID->"54351568-d786-4022-b83b-\
5e4d660a5893"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{
  RowBox[{"Hb", "/.", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"a", "\[Rule]", "0"}], ",", 
     RowBox[{"l", "\[Rule]", "64"}], ",", 
     RowBox[{"M", "\[Rule]", "1024"}], ",", 
     RowBox[{"n", "\[Rule]", "128"}]}], "}"}]}], "//", "N"}]], "Input",
 CellChangeTimes->{{3.7893947212820253`*^9, 3.789394746785488*^9}, {
   3.7893949849161167`*^9, 3.789395044964634*^9}, {3.789395086109042*^9, 
   3.789395102932963*^9}, {3.7893952419827337`*^9, 3.7893952524073133`*^9}, {
   3.789395445120874*^9, 3.789395455104025*^9}, 3.78939725355352*^9, {
   3.7894021529984627`*^9, 3.789402188990449*^9}, {3.7894022682954893`*^9, 
   3.7894022685430202`*^9}, {3.7894032984330893`*^9, 3.789403300104393*^9}, {
   3.789459622649514*^9, 3.7894596529210587`*^9}, {3.789460982950026*^9, 
   3.789460983237506*^9}, {3.789461019238312*^9, 3.7894610589020977`*^9}, {
   3.789462072520067*^9, 3.789462083751606*^9}, {3.789463293219452*^9, 
   3.789463311898932*^9}, {3.789465032267406*^9, 
   3.789465042259001*^9}},ExpressionUUID->"9f38c281-0266-4a4e-be5f-\
c7b9be41e040"],

Cell[BoxData["2730.6666666666665`"], "Output",
 CellChangeTimes->{{3.789460640809956*^9, 3.789460647610591*^9}, {
   3.78946097843635*^9, 3.789460984333621*^9}, {3.78946102005573*^9, 
   3.789461059358095*^9}, {3.7894620698001547`*^9, 3.7894620841843853`*^9}, 
   3.789462121649454*^9, {3.789463286162388*^9, 3.789463312643051*^9}, 
   3.7894633433163443`*^9, 3.789463391501738*^9, {3.789465029197392*^9, 
   3.789465042690243*^9}},ExpressionUUID->"a011d789-9eb0-4e3e-99f9-\
4cbf4e877915"]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData["Hb"], "Input",
 CellChangeTimes->{{3.789406252892799*^9, 
  3.789406253275886*^9}},ExpressionUUID->"b9313e17-b444-4246-b93c-\
da4659fa1edf"],

Cell[BoxData[
 RowBox[{
  RowBox[{"a", " ", 
   RowBox[{"(", 
    RowBox[{"1", "+", 
     RowBox[{"Ceiling", "[", 
      FractionBox["M", "l"], "]"}], "-", 
     RowBox[{"Ceiling", "[", 
      FractionBox["n", "l"], "]"}]}], ")"}]}], "+", 
  FractionBox[
   RowBox[{"2", " ", "l", " ", "n", " ", 
    RowBox[{"Ceiling", "[", 
     FractionBox["M", "l"], "]"}], " ", 
    RowBox[{"(", 
     RowBox[{"1", "+", 
      RowBox[{"Ceiling", "[", 
       FractionBox[
        RowBox[{"Log", "[", 
         RowBox[{"Ceiling", "[", 
          FractionBox["n", "l"], "]"}], "]"}], 
        RowBox[{"Log", "[", "2", "]"}]], "]"}]}], ")"}]}], 
   RowBox[{"l", "+", "n"}]]}]], "Output",
 CellChangeTimes->{3.7894062536623497`*^9, 3.7894063313403263`*^9, 
  3.789463394539165*^9},ExpressionUUID->"bcb73b3c-e85a-4192-b487-\
1a21c4e1963a"]
}, Open  ]]
},
WindowSize->{1909, 1822},
WindowMargins->{{Automatic, 0}, {0, Automatic}},
Magnification:>1.5 Inherited,
FrontEndVersion->"11.2 for Linux x86 (64-bit) (September 10, 2017)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 561, 13, 119, "Input",ExpressionUUID->"04e5085a-4ff9-4d50-b19b-083b558526b6"],
Cell[CellGroupData[{
Cell[1144, 37, 837, 19, 53, "Input",ExpressionUUID->"ea6f14b4-a2fb-45ea-a4c3-bd72323380f9"],
Cell[1984, 58, 1043, 18, 59, "Output",ExpressionUUID->"6cdc7651-732c-497e-9a81-da71969e4fba"]
}, Open  ]],
Cell[3042, 79, 812, 22, 118, "Input",ExpressionUUID->"7ba8422a-20a9-495a-a0c7-5edcaa0eb031"],
Cell[3857, 103, 12105, 246, 1139, "Input",ExpressionUUID->"fef9122d-67b4-458a-a3dc-0f08d8bc6a61"],
Cell[CellGroupData[{
Cell[15987, 353, 1797, 41, 189, "Input",ExpressionUUID->"0b3bb483-359c-4254-9b33-4236a01c1ffa"],
Cell[CellGroupData[{
Cell[17809, 398, 1166, 19, 37, "Print",ExpressionUUID->"f7471907-0dcc-4cfc-913a-1f30bcc63050"],
Cell[18978, 419, 1164, 19, 37, "Print",ExpressionUUID->"b33ddc99-242a-47c1-aa6c-83693b6605bb"],
Cell[20145, 440, 1164, 19, 37, "Print",ExpressionUUID->"e212f8f0-5ca0-4500-8fd4-33fb8eff3d19"],
Cell[21312, 461, 1165, 19, 37, "Print",ExpressionUUID->"6c9741b5-da27-4705-a7a8-435eb2639de1"]
}, Open  ]]
}, Open  ]],
Cell[22504, 484, 2502, 59, 347, "Input",ExpressionUUID->"c183fee1-f76a-49fb-9eba-406d0d314017"],
Cell[25009, 545, 1557, 34, 144, "Input",ExpressionUUID->"9b89251b-6542-44c3-b076-f04565361aee"],
Cell[CellGroupData[{
Cell[26591, 583, 540, 9, 48, "Input",ExpressionUUID->"392a23f7-4324-481d-849c-2aadb1bc67bf"],
Cell[27134, 594, 829, 25, 135, "Output",ExpressionUUID->"54351568-d786-4022-b83b-5e4d660a5893"]
}, Open  ]],
Cell[CellGroupData[{
Cell[28000, 624, 1080, 20, 48, "Input",ExpressionUUID->"9f38c281-0266-4a4e-be5f-c7b9be41e040"],
Cell[29083, 646, 489, 7, 78, "Output",ExpressionUUID->"a011d789-9eb0-4e3e-99f9-4cbf4e877915"]
}, Open  ]],
Cell[CellGroupData[{
Cell[29609, 658, 154, 3, 48, "Input",ExpressionUUID->"b9313e17-b444-4246-b93c-da4659fa1edf"],
Cell[29766, 663, 822, 24, 125, "Output",ExpressionUUID->"bcb73b3c-e85a-4192-b487-1a21c4e1963a"]
}, Open  ]]
}
]
*)

